package com.qriver.session.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 登录
 */
@Controller
public class LoginController {

    /**
     * 跳转登录界面
     * @return
     */
    @RequestMapping("login")
    public String login(){
        return "login";
    }

    @RequestMapping("doLogin")
    public String doLogin(HttpServletRequest request, HttpServletResponse response,String username, String password){
        if("admin".equals(username) && "admin".equals(password)){
            //1、创建session
            request.getSession().setAttribute("username","admin");
            return "redirect:index";
        }
        return "redirect:login";
    }
}
